/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('documentautoml', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model CreateModelAsyncPredictRequest {
  binaryToText?: boolean(name='BinaryToText'),
  body?: string(name='Body', example=''),
  content?: string(name='Content', example='https://doc-automl-public.oss-cn-hangzhou.aliyuncs.com/3/1559855998794593/stage/upload/20230206/oss-hlfCRJ1SorSWs10MkqxK6YcL4OVAFSv4.png?Expires=1675665563&OSSAccessKeyId=XXXX&Signature=WLKghBc3zKzWJ3Td69%2B4C21jrbE%3D'),
  modelId?: long(name='ModelId', example='123'),
  modelVersion?: string(name='ModelVersion', example='V1'),
  serviceName?: string(name='ServiceName', example='pre_train_service'),
  serviceVersion?: string(name='ServiceVersion', example='V1'),
}

model CreateModelAsyncPredictResponseBody = {
  code?: int32(name='Code', example='200'),
  data?: string(name='Data', example='{
  "RequestId": "292D1584-134C-1221-B9BB-1B847C623D41",
  "Message": "",
  "Data": 1,
  "Code": 200
}'),
  message?: string(name='Message', example='success'),
  requestId?: string(name='RequestId', description='Id of the request', example='3EAC98E6-8DD6-511F-8764-DEE8B6EB6BB4'),
}

model CreateModelAsyncPredictResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: CreateModelAsyncPredictResponseBody(name='body'),
}

async function createModelAsyncPredictWithOptions(request: CreateModelAsyncPredictRequest, runtime: Util.RuntimeOptions): CreateModelAsyncPredictResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.binaryToText)) {
    query['BinaryToText'] = request.binaryToText;
  }
  if (!Util.isUnset(request.content)) {
    query['Content'] = request.content;
  }
  if (!Util.isUnset(request.modelId)) {
    query['ModelId'] = request.modelId;
  }
  if (!Util.isUnset(request.modelVersion)) {
    query['ModelVersion'] = request.modelVersion;
  }
  if (!Util.isUnset(request.serviceName)) {
    query['ServiceName'] = request.serviceName;
  }
  if (!Util.isUnset(request.serviceVersion)) {
    query['ServiceVersion'] = request.serviceVersion;
  }
  var body : map[string]any = {};
  if (!Util.isUnset(request.body)) {
    body['Body'] = request.body;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'CreateModelAsyncPredict',
    version = '2022-12-29',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function createModelAsyncPredict(request: CreateModelAsyncPredictRequest): CreateModelAsyncPredictResponse {
  var runtime = new Util.RuntimeOptions{};
  return createModelAsyncPredictWithOptions(request, runtime);
}

model GetModelAsyncPredictRequest {
  asyncPredictId?: long(name='AsyncPredictId', example='1'),
}

model GetModelAsyncPredictResponseBody = {
  code?: int32(name='Code', example='200'),
  data?: string(name='Data', example='{
  "RequestId": "A9796F06-F1C4-1E89-8AFD-596583FF4B16",
  "Message": "",
  "Data": {
    "result": "https://doc-automl-public.oss-cn-hangzhou.aliyuncs.com/3/stage/data/XXXX/asyncPredict/713908/oss-933bbdf4-fa10-4c56-b6ab-9c85f32bbd0e.json?Expires=1991115127&OSSAccessKeyId=XXXX&Signature=5zYLY9yR%2B9Ok1WuRgHYdqtXHK10%3D",
    "asyncPredictId": 713908,
    "errorCode": 200,
    "errorMsg": "",
    "status": 2
  },
  "Code": 200
}'),
  message?: string(name='Message', example='success'),
  requestId?: string(name='RequestId', description='Id of the request', example='3EAC98E6-8DD6-511F-8764-DEE8B6EB6BB4'),
}

model GetModelAsyncPredictResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetModelAsyncPredictResponseBody(name='body'),
}

async function getModelAsyncPredictWithOptions(request: GetModelAsyncPredictRequest, runtime: Util.RuntimeOptions): GetModelAsyncPredictResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.asyncPredictId)) {
    query['AsyncPredictId'] = request.asyncPredictId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetModelAsyncPredict',
    version = '2022-12-29',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getModelAsyncPredict(request: GetModelAsyncPredictRequest): GetModelAsyncPredictResponse {
  var runtime = new Util.RuntimeOptions{};
  return getModelAsyncPredictWithOptions(request, runtime);
}

model PredictClassifierModelRequest {
  autoPrediction?: boolean(name='AutoPrediction', example='true'),
  binaryToText?: boolean(name='BinaryToText'),
  body?: string(name='Body', example=''),
  classifierId?: long(name='ClassifierId'),
  content?: string(name='Content'),
}

model PredictClassifierModelResponseBody = {
  code?: int32(name='Code', example='200'),
  data?: map[string]any(name='Data'),
  message?: string(name='Message', example='success'),
  requestId?: string(name='RequestId', description='Id of the request', example='232B91A8-9938-5C10-B522-127D1E342A57'),
}

model PredictClassifierModelResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: PredictClassifierModelResponseBody(name='body'),
}

async function predictClassifierModelWithOptions(request: PredictClassifierModelRequest, runtime: Util.RuntimeOptions): PredictClassifierModelResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.autoPrediction)) {
    query['AutoPrediction'] = request.autoPrediction;
  }
  if (!Util.isUnset(request.binaryToText)) {
    query['BinaryToText'] = request.binaryToText;
  }
  if (!Util.isUnset(request.classifierId)) {
    query['ClassifierId'] = request.classifierId;
  }
  if (!Util.isUnset(request.content)) {
    query['Content'] = request.content;
  }
  var body : map[string]any = {};
  if (!Util.isUnset(request.body)) {
    body['Body'] = request.body;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'PredictClassifierModel',
    version = '2022-12-29',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function predictClassifierModel(request: PredictClassifierModelRequest): PredictClassifierModelResponse {
  var runtime = new Util.RuntimeOptions{};
  return predictClassifierModelWithOptions(request, runtime);
}

model PredictModelRequest {
  binaryToText?: boolean(name='BinaryToText'),
  body?: string(name='Body', example=''),
  content?: string(name='Content'),
  modelId?: long(name='ModelId', example='123'),
  modelVersion?: string(name='ModelVersion', example='1'),
}

model PredictModelResponseBody = {
  code?: int32(name='Code', example='200'),
  data?: map[string]any(name='Data'),
  message?: string(name='Message', example='success'),
  requestId?: string(name='RequestId', description='Id of the request', example='3EAC98E6-8DD6-511F-8764-DEE8B6EB6BB4'),
}

model PredictModelResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: PredictModelResponseBody(name='body'),
}

async function predictModelWithOptions(request: PredictModelRequest, runtime: Util.RuntimeOptions): PredictModelResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.binaryToText)) {
    query['BinaryToText'] = request.binaryToText;
  }
  if (!Util.isUnset(request.content)) {
    query['Content'] = request.content;
  }
  if (!Util.isUnset(request.modelId)) {
    query['ModelId'] = request.modelId;
  }
  if (!Util.isUnset(request.modelVersion)) {
    query['ModelVersion'] = request.modelVersion;
  }
  var body : map[string]any = {};
  if (!Util.isUnset(request.body)) {
    body['Body'] = request.body;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'PredictModel',
    version = '2022-12-29',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function predictModel(request: PredictModelRequest): PredictModelResponse {
  var runtime = new Util.RuntimeOptions{};
  return predictModelWithOptions(request, runtime);
}

model PredictPreTrainModelRequest {
  binaryToText?: boolean(name='BinaryToText', example='false'),
  body?: string(name='Body'),
  content?: string(name='Content'),
  serviceName?: string(name='ServiceName', example='FormUIE'),
  serviceVersion?: string(name='ServiceVersion', example='V1'),
}

model PredictPreTrainModelResponseBody = {
  code?: int32(name='Code', example='200'),
  data?: map[string]any(name='Data'),
  message?: string(name='Message', example='success'),
  requestId?: string(name='RequestId', description='Id of the request', example='29413C69-11EF-15CB-BE20-70D318E2F4E9'),
}

model PredictPreTrainModelResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: PredictPreTrainModelResponseBody(name='body'),
}

async function predictPreTrainModelWithOptions(request: PredictPreTrainModelRequest, runtime: Util.RuntimeOptions): PredictPreTrainModelResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.binaryToText)) {
    query['BinaryToText'] = request.binaryToText;
  }
  if (!Util.isUnset(request.content)) {
    query['Content'] = request.content;
  }
  if (!Util.isUnset(request.serviceName)) {
    query['ServiceName'] = request.serviceName;
  }
  if (!Util.isUnset(request.serviceVersion)) {
    query['ServiceVersion'] = request.serviceVersion;
  }
  var body : map[string]any = {};
  if (!Util.isUnset(request.body)) {
    body['Body'] = request.body;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'PredictPreTrainModel',
    version = '2022-12-29',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function predictPreTrainModel(request: PredictPreTrainModelRequest): PredictPreTrainModelResponse {
  var runtime = new Util.RuntimeOptions{};
  return predictPreTrainModelWithOptions(request, runtime);
}

model PredictTemplateModelRequest {
  binaryToText?: boolean(name='BinaryToText'),
  body?: string(name='Body', example=''),
  content?: string(name='Content'),
  taskId?: long(name='TaskId'),
}

model PredictTemplateModelResponseBody = {
  code?: string(name='Code', example='200'),
  data?: map[string]any(name='Data'),
  message?: string(name='Message', example='successful'),
  requestId?: string(name='RequestId', description='Id of the request', example='F25FBAB4-665A-5D85-8AEF-39AE29F7D588'),
}

model PredictTemplateModelResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: PredictTemplateModelResponseBody(name='body'),
}

async function predictTemplateModelWithOptions(request: PredictTemplateModelRequest, runtime: Util.RuntimeOptions): PredictTemplateModelResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.binaryToText)) {
    query['BinaryToText'] = request.binaryToText;
  }
  if (!Util.isUnset(request.content)) {
    query['Content'] = request.content;
  }
  if (!Util.isUnset(request.taskId)) {
    query['TaskId'] = request.taskId;
  }
  var body : map[string]any = {};
  if (!Util.isUnset(request.body)) {
    body['Body'] = request.body;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'PredictTemplateModel',
    version = '2022-12-29',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function predictTemplateModel(request: PredictTemplateModelRequest): PredictTemplateModelResponse {
  var runtime = new Util.RuntimeOptions{};
  return predictTemplateModelWithOptions(request, runtime);
}

